<?php
	require '../include/library.inc.php';
	require '../include/admin_login.inc.php';
		
if (!isset($_POST['is_submitted'])) {
	$_POST['is_submitted'] = '';
}
if (!isset($error_message)) {
	$error_message = '';
}	
$order_id = $_GET["order_id"];

if($_POST["redirect"] || $_SESSION['redirect'] ){
	if($_POST["redirect"]) $redirect = $_POST["redirect"];
	if($_SESSION['redirect']){ 
	$redirect = $_SESSION['redirect'];
	unset($_SESSION['redirect']);
	}
}else{
       $redirect = $_SERVER['HTTP_REFERER'];	
     }
	
if ($_POST['is_submitted']) {
		$error_message = '';
		$redirect = $_POST["redirect"];
    
	
		
		$sql = "UPDATE orders SET
				  status = '".intval($_POST['status'])."',
				  note = '".escape($_POST['note'])."',
				  institution = '".escape($_POST['institution'])."'
				 
				 WHERE
				 order_id = '$order_id'
				";
		query($sql);

		
		
		
		$_SESSION['message'] .= 'Регистрацията е редактирана успешно!';
        
		if($_POST["redirectForm"]){
           redirect($_POST["redirectForm"]);
		}else{
			$_SESSION['redirect'] = $redirect;
		   redirect(HTML_BASE_ADMIN.'order_edit.php?order_id='.$order_id);
		   
		   
		}
    }


	
	head_admin("Преглед на регистрацията");
?>

            <?php if ($error_message) { ?>
			<div class="message red">
				<h3>Грешка!</h3>
				<?=$error_message?>
			</div>
			<?php } ?>
			
            <div class="topbuttons">
            	<a href="<?=$redirect?>">Обратно</a>
            </div>
			
            <h3>Преглед на регистрацията</h3>
<?php

			
			$sql = "SELECT
					order_id,
					order_date,
					firstname,
					lastname,
					email,
					country,
					continent,
					institution,
					status,
					note,
					price,
					paypal,
					iass,
					culinary,
					dinner,
					allergic,
					byear
					
				FROM
					orders
				WHERE
				    order_id ='$order_id'
					
					";
			$result_cat = query($sql);
			$row = mysql_fetch_object($result_cat);
			
			
	  		?>
     
     
             
            
<form id="order_form_id" action="<?=$_SERVER['PHP_SELF']?>?order_id=<?=$order_id?>" method="post" enctype="multipart/form-data">
            <input type="hidden" name="is_submitted" value="1" />
			<input type="hidden" name="redirect" value="<?=$redirect?>" />
             <input id="redirectForm" type="hidden" name="redirectForm" value="" />
            
        	<table id="listing" width="100%" cellpadding="0" cellspacing="0">
					<thead>
                        <tr>
                            <td>Регистрация №</td>
                            <td><?=number_pad($row->order_id,5)?></td>
                        </tr>
                    </thead>
				<tbody>
                <tr>
                	<td>
                    <b>Име:</b>
                    </td>
                    <td>
                    <?=$row->firstname?> <?=$row->lastname?>
                    </td>
                </tr>
                	<td>
                    <b>E-mail:</b>
                    </td>
                    <td>
                    <a href="mailto:<?=$row->email?>"><?=$row->email?></a>
                    </td>
                <tr>
                </tr>
                	<td>
                    <b>Набор:</b>
                    </td>
                    <td>
                    <?=$row->byear?> г.
                    </td>
                <tr>
                	<td>
                    <b>Дъжава:</b>
                    </td>
                    <td>
                    <?=$row->country?>,
                                
								<?php if($row->continent == 1){?> Европа <?php }?>
								<?php if($row->continent == 2){?> Извън европа <?php }?>
                                <?php if($row->continent == 3){?> Африка <?php }?>	
                    </td>
                </tr>
                <tr>
                	<td>
                    <b>Институция:</b>
                    </td>
                    <td>
                     <input class="inputbox" name="institution" value="<?=$row->institution?>" >
                    </td>
                </tr>
                <tr>
                    <td>
                    <b>Дата:</b>
                    </td>
                    <td>
                    <?=date('d.m.Y', strtotime($row->order_date))?>
                    </td>
                </tr>
                
                
                
              
            
			                
                             <?php if($row->allergic){?>
                            <tr> 
                             	<td>
                            
                                </td>
                                <td>
                                <b><span style="color:#900">Алергичен/a!</span></b>
                                </td>
                               </tr>
							 <?php }?>
                             
                            
                             
                             <?php if($row->iass){?>
                             
                             <tr> 
                             	<td>
                            
                                </td>
                                <td>
                                <b>+ IASS/AIS<b>
                                </td>
                               </tr>
                             
							 <?php }?>
                             
                            
                            
                            
                             <?php if($row->culinary){?>
                             <tr> 
                             	<td>
                            
                                </td>
                                <td>
                                <b>+ Culinary show<b>
                                </td>
                               </tr>
                              
							 
							 <?php }?>
                            
                            
                            
                           
                            <?php if($row->dinner){?>
                            <tr> 
                             	<td>
                            
                                </td>
                                <td>
                                 <b>+ Gala dinner<b>
                                </td>
                               </tr>
                            
							<?php }?>
                           
			    <tr>
                	<td>
                    <b>Сума:</b>
                    </td>
                    <td>
                    <b><?=$row->price?> €</b>
                    </td>
                </tr>
 			
            <tr>
                	<td>
                    <b>PayPal:</b>
                    </td>
                    <td>
                    <?=urldecode($row->paypal)?> 
                    </td>
                </tr>
                
              <tr>
                	<td>
                    <b>Статус:</b>
                    </td>
                    <td>   
			<select  name="status">
                <option value="0" <?php if($row->status == 0){?> selected="selected"<?php }?> >Неплатена</option>
                <option value="0" <?php if($row->status == 4){?> selected="selected"<?php }?> >Грешка при плащане</option>
                <option value="1" <?php if($row->status == 1){?> selected="selected"<?php }?> >Отказана</option>
                <option value="2" <?php if($row->status == 2){?> selected="selected"<?php }?> >Платена</option>
            </select>
             </td>
                </tr>
                
                
           <tr>
                	<td>
                    <b>Забележка:</b>
                    </td>
                    <td>  
            <textarea   class="inputbox"  name="note" rows="10"><?=sth($row->note)?></textarea>
            </td>
                </tr>
            
		 </tbody>
        </table>
						
			</form>    
      
            
            
<?php
	controls($redirect, "#order_form_id");
	foot_admin(); 
?>